import axios from "axios";
import { useUserStore } from '@/store/user'
import { storeToRefs } from 'pinia'

const instance = axios.create({
    baseURL: import.meta.env.VITE_APP_API
});

instance.interceptors.request.use(function (config) {
    const store = useUserStore();
    let { userInfo } = storeToRefs(store)
    if(userInfo.value !== null){
        config.headers.Authorization = `Token ${userInfo.value?.token}`
    }

    return config;
  });

export default instance